package com.gwnet.user.controller;

import com.gwnet.common.bean.vo.LoginVO;
import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.user.domain.CusUser;
import com.gwnet.user.domain.bo.UserLoginBO;
import com.gwnet.user.entity.bo.SendSmsBO;
import com.gwnet.user.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.BindException;

/**
 * 1.通过social码获取用户的openId并保存到系统
 * 2.发送短信注册/登录一般来说是第二步，用于绑定openId和用户的手机号；
 * 3.将用户手机号等信息保存到数据库；
 *
 * @author: WangLiang
 * @date: 2024/7/20 10:36
 */
@RequestMapping("/login")
@RestController
public class LoginController {

    private final LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    /**
     * 发送短信验证码
     * @param sendSmsBO
     * @return
     */
    @PostMapping("/sendSms")
    public ResponseResult<Boolean> sendSms(@RequestBody SendSmsBO sendSmsBO){
        Boolean flag = loginService.sendSms(sendSmsBO.getPhone());
        return ResponseResult.success(flag);
    }

    /**
     * 发送短信 注册/登录
     * @param userLoginBO
     * @return
     */
    @PostMapping("/smsRegOrLogin")
    public ResponseResult<LoginVO> smsRegOrLogin(@RequestBody UserLoginBO userLoginBO) {
        LoginVO loginVO = loginService.smsRegOrLogin(userLoginBO);
        return ResponseResult.success(loginVO);
    }
}
